export default class Heroe {
  constructor(info) {
    // 赋值武将属性
    Object.assign(this, info);
  }
  /**
   * 武将是否招募
   */
  get isEnlist() {
    let ids = [];
    try {
      ids = window.stateData.userHeroes || [];
    } catch (err) {
      console.log(err);
    }
    return ids.indexOf(this.id) !== -1;
  }
  /**
   * 获取国家名称
   */
  get countryName() {
    let arr = ["魏", "蜀", "吴", "群"];
    return arr[this.country - 1];
  }
  /**
   * 获取骑兵等级
   */
  get cavalryLevel() {
    let arr = ["C", "B", "A", "S"];
    return arr[this.cavalry - 1];
  }
  /**
   * 获取盾兵等级
   */
  get maulerLevel() {
    let arr = ["C", "B", "A", "S"];
    return arr[this.mauler - 1];
  }
  /**
   * 获取弓兵等级
   */
  get archerLevel() {
    let arr = ["C", "B", "A", "S"];
    return arr[this.archer - 1];
  }
  /**
   * 获取枪兵等级
   */
  get pikemanLevel() {
    let arr = ["C", "B", "A", "S"];
    return arr[this.pikeman - 1];
  }
  /**
   * 获取器械等级
   */
  get weaponLevel() {
    let arr = ["C", "B", "A", "S"];
    return arr[this.weapon - 1];
  }
  /**
   * 获取武将自带战法
   */
  getHeroeTactic() {
    let tacticsList = window.stateData.tacticsList;
    let list = [];
    tacticsList.forEach((item) => {
      let ids = item.born_tactic_heroes || [];
      if (ids.indexOf(this.id) !== -1) list.push(item);
    });
    return list;
  }
  /**
   * 获取武将传承战法
   */
  getInheritTactic() {
    let tacticsList = window.stateData.tacticsList;
    let list = [];
    tacticsList.forEach((item) => {
      let ids = item.inherit_tactic_heroes || [];
      if (ids.indexOf(this.id) !== -1) list.push(item);
    });
    return list;
  }
  getAttrName(attr) {
    let obj = {
      control: "统御",
      command: "统率",
      force: "武力",
      statecraft: "政治",
      intelligence: "智力",
      charm: "魅力",
      speed: "速度",
    };
    return obj[attr];
  }
  // 获取推荐兵书
  getRecommendBook() {
    let booksList = window.stateData.booksList;
    let list = [];
    let ids = this.recommend_book_ids || [];
    booksList.forEach((item) => {
      if (ids.indexOf(item.id) !== -1) list.push(item);
    });
    return list;
  }
  // 获取推荐战法
  getRecommendTactic() {
    let tacticsList = window.stateData.tacticsList;
    let ids = Array.isArray(this.recommend_tactic_ids)
      ? this.recommend_tactic_ids
      : [];
    let list = [];
    tacticsList.forEach((item) => {
      if (ids.indexOf(item.id) !== -1) list.push(item);
    });
    return list;
  }
}
